package net.ifilm.dao;

import com.ibatis.sqlmap.client.SqlMapClient;
import net.ifilm.entity.Star;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <code>StarDao</code>类主要对于电影主演表的数据库操作
 *
 * @author wangjunneil@gmail.com
 */
@Repository
public class StarDao extends SqlMapClientDaoSupport {
    
    @Autowired
    public void setSqlMapClientOverride(SqlMapClient sqlMapClient) {
        super.setSqlMapClient(sqlMapClient);
    }

    // ---------------------------------------------------------------------------------------- business method

    /**
     * 根据明星名称查询记录
     *
     * @return 明星对象
     */
    public List<Star> queryStar(Map<String, Object> parameter) {
        return getSqlMapClientTemplate().queryForList("queryStar", parameter);
    }

    /**
     * 向数据库增加一条明星记录信息
     *
     * @param star 明星对象
     * @return 主键ID
     */
    public int insertStar(Star star) {
        return (Integer)getSqlMapClientTemplate().insert("insertStar", star);
    }

    /**
     * 关联电影与明星关系
     *
     * @param parameterMap 参数表
     */
    public void relFilmStar(Map<String, Object> parameterMap) {
        getSqlMapClientTemplate().insert("relFilmStar", parameterMap);
    }

    /**
     * 根据电影ID删除主演关联纪录
     *
     * @param filmId
     */
    public void deleteRelFilmStar(int filmId) {
        getSqlMapClientTemplate().delete("delRelFilmStar", filmId);
    }
    
    public void deleteRelFilmStar(Map<String, Object> parameter) {
        getSqlMapClientTemplate().delete("delRelStar", parameter);
    }
    
} ///:~
